<template>
    <el-aside width="200" hight="1200">
        <el-menu router active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" text-color="#fff">
            <el-menu-item :index="item.path" v-for="(item, index) in noChildren()" :key="item.path">
                <el-icon>
                    <location />
                </el-icon>
                <span>{{ item.label }}</span>
            </el-menu-item>

            <el-sub-menu :index="item.path" v-for="(item, index) in hasChildren()" :key="item.path">
                <template #title>
                    <el-icon>
                        <location />
                    </el-icon>
                    <span>{{ item.label }}</span>
                </template>
                <el-menu-item-group>
                    <el-menu-item v-for="childs in item.children" :index="item.path+'/'+childs.path">{{ childs.label }}</el-menu-item>
                </el-menu-item-group>
            </el-sub-menu>
        </el-menu>
    </el-aside>
</template>

<script setup lang='ts'>
interface RootObject {
    path?: string;
    name?: string;
    label: string;
    icon: string;
    url?: string;
    children?: Child[];
}

interface Child {
    path: string;
    name: string;
    label: string;
    icon: string;
    url: string;
}
import { onMounted, ref } from 'vue';
const list = ref<Array<RootObject>>([])
onMounted(() => {
    const localList = localStorage.getItem('menuList')
    list.value = JSON.parse(localList!)
    console.log(list.value);

})
const noChildren = () => list.value.filter((item: RootObject) => !item.children)
const hasChildren = () => list.value.filter((item: RootObject) => item.children)
</script>

<style scoped lang="less"></style>